package me.zhengjie.pm.workerlist.rest;

import me.zhengjie.aop.log.Log;
import me.zhengjie.pm.workerlist.domain.EmployeeCenterDepartView;
import me.zhengjie.pm.workerlist.service.EmployeeCenterDepartViewService;
import me.zhengjie.pm.workerlist.service.dto.EmployeeCenterDepartViewQueryCriteria;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

/**
* @author yuxj
* @date 2020-04-15
*/
@Api(tags = "员工清单管理")
@RestController
@RequestMapping("/api/employeeCenterDepartView")
public class EmployeeCenterDepartViewController {

    private final EmployeeCenterDepartViewService employeeCenterDepartViewService;

    public EmployeeCenterDepartViewController(EmployeeCenterDepartViewService employeeCenterDepartViewService) {
        this.employeeCenterDepartViewService = employeeCenterDepartViewService;
    }

    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('employeeCenterDepartView:list')")
    public void download(HttpServletResponse response, EmployeeCenterDepartViewQueryCriteria criteria) throws IOException {
        employeeCenterDepartViewService.download(employeeCenterDepartViewService.queryAll(criteria), response);
    }

    @GetMapping
    @Log("查询员工清单")
    @ApiOperation("查询员工清单")
    @PreAuthorize("@el.check('employeeCenterDepartView:list')")
    public ResponseEntity<Object> getEmployeeCenterDepartViews(EmployeeCenterDepartViewQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(employeeCenterDepartViewService.queryAll(criteria,pageable),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增员工清单")
    @ApiOperation("新增员工清单")
    @PreAuthorize("@el.check('employeeCenterDepartView:add')")
    public ResponseEntity<Object> create(@Validated @RequestBody EmployeeCenterDepartView resources){
        return new ResponseEntity<>(employeeCenterDepartViewService.create(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改员工清单")
    @ApiOperation("修改员工清单")
    @PreAuthorize("@el.check('employeeCenterDepartView:edit')")
    public ResponseEntity<Object> update(@Validated @RequestBody EmployeeCenterDepartView resources){
        employeeCenterDepartViewService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @Log("删除员工清单")
    @ApiOperation("删除员工清单")
    @PreAuthorize("@el.check('employeeCenterDepartView:del')")
    @DeleteMapping
    public ResponseEntity<Object> deleteAll(@RequestBody Integer[] ids) {
        employeeCenterDepartViewService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}